package cn.yangliu.ueditor;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.lang.reflect.Field;

/**
 * 作者 杨柳
 * 创建时间 2017-09-04 00:13
 */
@ConfigurationProperties(prefix = "spring.ueditor")
public class UEditorProperties {

    //////////////////////////公共配置/////////////////////////////
    private String globalUrlPreffix = "";

    private String globalSavePathPreffix = "";

    private String toolbars = "fullscreen,source,|,undo,redo,|,bold,italic,underline,fontborder,strikethrough,superscript,subscript,removeformat," +
            "formatmatch,autotypeset,blockquote,pasteplain,|,forecolor,backcolor,insertorderedlist,insertunorderedlist,selectall,cleardoc,|," +
            "rowspacingtop,rowspacingbottom,lineheight,|,customstyle,paragraph,fontfamily,fontsize,|,directionalityltr,directionalityrtl," +
            "indent,|,justifyleft,justifycenter,justifyright,justifyjustify,|,touppercase,tolowercase,|,link,unlink,anchor,|," +
            "imagenone,imageleft,imageright,imagecenter,|,simpleupload,insertimage,emotion,scrawl,insertvideo,attachment," +
            "map,insertframe,insertcode,webapp,pagebreak,template,background,|,horizontal,date,time,spechars,snapscreen,wordimage,|," +
            "inserttable,deletetable,insertparagraphbeforetable,insertrow,deleterow,insertcol,deletecol,mergecells,mergeright,mergedown," +
            "splittocells,splittorows,splittocols,charts,|,print,preview,searchreplace,help,drafts";

    private String serverUrl;

    ////////////////////////////图片上传配置/////////////////////////////////
    private String imageUrlPrefix = "";
    //执行上传图片的action名称
    private String imageActionName = "uploadimage";
    //提交的图片表单名称
    private String imageFieldName = "upfile";
    //上传大小限制，单位B
    private Long imageMaxSize = 2048000L;
    //上传图片格式显示
    private String imageAllowFiles = ".png,.jpg,.jpeg,.gif,.bmp";
    //是否压缩图片,默认是true
    private Boolean imageCompressEnable = true;
    //图片压缩最长边限制
    private Integer imageCompressBorder = 1600;
    //插入的图片浮动方式
    private String imageManagerInsertAlign = "none";
    //上传保存路径,可以自定义保存路径和文件名格式
    private String imagePathFormat = "/ueditor/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}";

    ////////////////////////////////////////涂鸦图片上传配置项//////////////////////////////////////////////
    //图片访问路径前缀
    private String scrawlUrlPrefix = "";
    //执行上传涂鸦的action名称
    private String scrawlActionName = "uploadscrawl";
    //提交的图片表单名称
    private String scrawlFieldName = "upfile";
    //插入的图片浮动方式
    private String scrawlInsertAlign = "none";
    //上传保存路径,可以自定义保存路径和文件名格式
    private String scrawlPathFormat = "/ueditor/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}";
    //上传大小限制，单位B
    private Long scrawlMaxSize = 2048000L;

    ////////////////////////////////////////////截图工具上传//////////////////////////////////////////////////
    //图片访问路径前缀
    private String snapscreenUrlPrefix = "";
    //执行上传截图的action名称
    private String snapscreenActionName = "uploadimage";
    //插入的图片浮动方式
    private String snapscreenInsertAlign = "none";
    //上传保存路径,可以自定义保存路径和文件名格式
    private String snapscreenPathFormat = "/ueditor/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}";

    //////////////////////////////////////////抓取远程图片配置////////////////////////////////////////////
    //图片访问路径前缀
    private String catcherUrlPrefix = "";
    //执行抓取远程图片的action名称
    private String catcherActionName = "catchimage";
    //抓取图片格式显示
    private String catcherAllowFiles = ".png,.jpg,.jpeg,.gif,.bmp";
    //上传保存路径,可以自定义保存路径和文件名格式
    private String catcherPathFormat = "/ueditor/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}";
    //上传大小限制，单位B
    private Long catcherMaxSize = 2048000L;
    //提交的图片列表表单名称
    private String catcherFieldName = "source";
    //我也不知道干嘛的 官方config.json没给注释
    private String catcherLocalDomain = "127.0.0.1,localhost,img.baidu.com";

    //////////////////////////////////////////////列出指定目录下的图片//////////////////////////////////////////////
    //图片访问路径前缀
    private String imageManagerUrlPrefix = "";
    //执行图片管理的action名称
    private String imageManagerActionName = "listimage";
    //列出的文件类型
    private String imageManagerAllowFiles = ".png,.jpg,.jpeg,.gif,.bmp";
    //指定要列出图片的目录
    private String imageManagerListPath = "/ueditor/upload/image/";
    //插入的图片浮动方式
    private String imageInsertAlign = "none";
    //每次列出文件数量
    private Integer imageManagerListSize = 20;

    ////////////////////////////////////////////////////上传文件配置////////////////////////////////////////////
    //文件访问路径前缀
    private String fileUrlPrefix = "";
    //执行上传文件的action名称
    private String fileActionName = "uploadfile";
    //提交的文件表单名称
    private String fileFieldName = "upfile";
    //上传保存路径,可以自定义保存路径和文件名格式
    private String filePathFormat = "/ueditor/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}";
    //上传大小限制，单位B，默认50MB
    private Long fileMaxSize = 51200000L;
    //上传文件格式显示
    private String fileAllowFiles = ".png,.jpg,.jpeg,.gif,.bmp,.flv,.swf,.mkv,.avi,.rm,.rmvb,.mpeg,.mpg,.ogg,.ogv,.mov,.wmv,.mp4,.webm,.mp3,.wav,.mid,.rar,.zip,.tar,.gz,.7z,.bz2,.cab,.iso,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.txt,.md,.xml";

    //////////////////////////////////////////列出指定目录下的文件//////////////////////////////////////////////
    //文件访问路径前缀
    private String fileManagerUrlPrefix = "";
    //执行文件管理的action名称
    private String fileManagerActionName = "listfile";
    //指定要列出文件的目录
    private String fileManagerListPath = "/ueditor/upload/file/";
    //列出的文件类型
    private String fileManagerAllowFiles = ".png,.jpg,.jpeg,.gif,.bmp,.flv,.swf,.mkv,.avi,.rm,.rmvb,.mpeg,.mpg,.ogg,.ogv,.mov,.wmv,.mp4,.webm,.mp3,.wav,.mid,.rar,.zip,.tar,.gz,.7z,.bz2,.cab,.iso,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.txt,.md,.xml";
    //每次列出文件数量
    private Integer fileManagerListSize = 20;

    ////////////////////////////////////////上传媒体配置////////////////////////////////////////////////
    //文件访问路径前缀
    private String mediaUrlPrefix = "";
    //提交的媒体表单名称
    private String mediaFieldName = "upfile";
    //提交的媒体表单名称
    private String mediaActionName = "uploadmedia";
    //上传大小限制，单位B，默认100MB
    private Long mediaMaxSize = 102400000L;
    //上传保存路径,可以自定义保存路径和文件名格式
    private String mediaPathFormat = "/ueditor/upload/media/{yyyy}{mm}{dd}/{time}{rand:6}";
    //上传媒体格式显示
    private String mediaAllowFiles = ".flv,.swf,.mkv,.avi,.rm,.rmvb,.mpeg,.mpg,.ogg,.ogv,.mov,.wmv,.mp4,.webm,.mp3,.wav,.mid";

    public String getGlobalUrlPreffix() {
        return globalUrlPreffix;
    }

    public void setGlobalUrlPreffix(String globalUrlPreffix) {
        this.globalUrlPreffix = globalUrlPreffix;
    }

    public String getGlobalSavePathPreffix() {
        return globalSavePathPreffix;
    }

    public void setGlobalSavePathPreffix(String globalSavePathPreffix) {
        this.globalSavePathPreffix = globalSavePathPreffix;
    }

    public String getImageUrlPrefix() {
        return imageUrlPrefix;
    }

    public void setImageUrlPrefix(String imageUrlPrefix) {
        this.imageUrlPrefix = imageUrlPrefix;
    }

    public String getImageActionName() {
        return imageActionName;
    }

    public void setImageActionName(String imageActionName) {
        this.imageActionName = imageActionName;
    }

    public String getImageFieldName() {
        return imageFieldName;
    }

    public void setImageFieldName(String imageFieldName) {
        this.imageFieldName = imageFieldName;
    }

    public Long getImageMaxSize() {
        return imageMaxSize;
    }

    public void setImageMaxSize(Long imageMaxSize) {
        this.imageMaxSize = imageMaxSize;
    }

    public String getImageAllowFiles() {
        return imageAllowFiles;
    }

    public void setImageAllowFiles(String imageAllowFiles) {
        this.imageAllowFiles = imageAllowFiles;
    }

    public Boolean getImageCompressEnable() {
        return imageCompressEnable;
    }

    public void setImageCompressEnable(Boolean imageCompressEnable) {
        this.imageCompressEnable = imageCompressEnable;
    }

    public Integer getImageCompressBorder() {
        return imageCompressBorder;
    }

    public void setImageCompressBorder(Integer imageCompressBorder) {
        this.imageCompressBorder = imageCompressBorder;
    }

    public String getImageManagerInsertAlign() {
        return imageManagerInsertAlign;
    }

    public void setImageManagerInsertAlign(String imageManagerInsertAlign) {
        this.imageManagerInsertAlign = imageManagerInsertAlign;
    }

    public String getImagePathFormat() {
        return imagePathFormat;
    }

    public void setImagePathFormat(String imagePathFormat) {
        this.imagePathFormat = imagePathFormat;
    }

    public String getScrawlUrlPrefix() {
        return scrawlUrlPrefix;
    }

    public void setScrawlUrlPrefix(String scrawlUrlPrefix) {
        this.scrawlUrlPrefix = scrawlUrlPrefix;
    }

    public String getScrawlActionName() {
        return scrawlActionName;
    }

    public void setScrawlActionName(String scrawlActionName) {
        this.scrawlActionName = scrawlActionName;
    }

    public String getScrawlFieldName() {
        return scrawlFieldName;
    }

    public void setScrawlFieldName(String scrawlFieldName) {
        this.scrawlFieldName = scrawlFieldName;
    }

    public String getScrawlInsertAlign() {
        return scrawlInsertAlign;
    }

    public void setScrawlInsertAlign(String scrawlInsertAlign) {
        this.scrawlInsertAlign = scrawlInsertAlign;
    }

    public String getScrawlPathFormat() {
        return scrawlPathFormat;
    }

    public void setScrawlPathFormat(String scrawlPathFormat) {
        this.scrawlPathFormat = scrawlPathFormat;
    }

    public Long getScrawlMaxSize() {
        return scrawlMaxSize;
    }

    public void setScrawlMaxSize(Long scrawlMaxSize) {
        this.scrawlMaxSize = scrawlMaxSize;
    }

    public String getSnapscreenUrlPrefix() {
        return snapscreenUrlPrefix;
    }

    public void setSnapscreenUrlPrefix(String snapscreenUrlPrefix) {
        this.snapscreenUrlPrefix = snapscreenUrlPrefix;
    }

    public String getSnapscreenActionName() {
        return snapscreenActionName;
    }

    public void setSnapscreenActionName(String snapscreenActionName) {
        this.snapscreenActionName = snapscreenActionName;
    }

    public String getSnapscreenInsertAlign() {
        return snapscreenInsertAlign;
    }

    public void setSnapscreenInsertAlign(String snapscreenInsertAlign) {
        this.snapscreenInsertAlign = snapscreenInsertAlign;
    }

    public String getSnapscreenPathFormat() {
        return snapscreenPathFormat;
    }

    public void setSnapscreenPathFormat(String snapscreenPathFormat) {
        this.snapscreenPathFormat = snapscreenPathFormat;
    }

    public String getCatcherUrlPrefix() {
        return catcherUrlPrefix;
    }

    public void setCatcherUrlPrefix(String catcherUrlPrefix) {
        this.catcherUrlPrefix = catcherUrlPrefix;
    }

    public String getCatcherActionName() {
        return catcherActionName;
    }

    public void setCatcherActionName(String catcherActionName) {
        this.catcherActionName = catcherActionName;
    }

    public String getCatcherAllowFiles() {
        return catcherAllowFiles;
    }

    public void setCatcherAllowFiles(String catcherAllowFiles) {
        this.catcherAllowFiles = catcherAllowFiles;
    }

    public String getCatcherPathFormat() {
        return catcherPathFormat;
    }

    public void setCatcherPathFormat(String catcherPathFormat) {
        this.catcherPathFormat = catcherPathFormat;
    }

    public Long getCatcherMaxSize() {
        return catcherMaxSize;
    }

    public void setCatcherMaxSize(Long catcherMaxSize) {
        this.catcherMaxSize = catcherMaxSize;
    }

    public String getCatcherFieldName() {
        return catcherFieldName;
    }

    public void setCatcherFieldName(String catcherFieldName) {
        this.catcherFieldName = catcherFieldName;
    }

    public String getCatcherLocalDomain() {
        return catcherLocalDomain;
    }

    public void setCatcherLocalDomain(String catcherLocalDomain) {
        this.catcherLocalDomain = catcherLocalDomain;
    }

    public String getImageManagerUrlPrefix() {
        return imageManagerUrlPrefix;
    }

    public void setImageManagerUrlPrefix(String imageManagerUrlPrefix) {
        this.imageManagerUrlPrefix = imageManagerUrlPrefix;
    }

    public String getImageManagerActionName() {
        return imageManagerActionName;
    }

    public void setImageManagerActionName(String imageManagerActionName) {
        this.imageManagerActionName = imageManagerActionName;
    }

    public String getImageManagerAllowFiles() {
        return imageManagerAllowFiles;
    }

    public void setImageManagerAllowFiles(String imageManagerAllowFiles) {
        this.imageManagerAllowFiles = imageManagerAllowFiles;
    }

    public String getImageManagerListPath() {
        return imageManagerListPath;
    }

    public void setImageManagerListPath(String imageManagerListPath) {
        this.imageManagerListPath = imageManagerListPath;
    }

    public String getImageInsertAlign() {
        return imageInsertAlign;
    }

    public void setImageInsertAlign(String imageInsertAlign) {
        this.imageInsertAlign = imageInsertAlign;
    }

    public Integer getImageManagerListSize() {
        return imageManagerListSize;
    }

    public void setImageManagerListSize(Integer imageManagerListSize) {
        this.imageManagerListSize = imageManagerListSize;
    }

    public String getFileUrlPrefix() {
        return fileUrlPrefix;
    }

    public void setFileUrlPrefix(String fileUrlPrefix) {
        this.fileUrlPrefix = fileUrlPrefix;
    }

    public String getFileActionName() {
        return fileActionName;
    }

    public void setFileActionName(String fileActionName) {
        this.fileActionName = fileActionName;
    }

    public String getFileFieldName() {
        return fileFieldName;
    }

    public void setFileFieldName(String fileFieldName) {
        this.fileFieldName = fileFieldName;
    }

    public String getFilePathFormat() {
        return filePathFormat;
    }

    public void setFilePathFormat(String filePathFormat) {
        this.filePathFormat = filePathFormat;
    }

    public Long getFileMaxSize() {
        return fileMaxSize;
    }

    public void setFileMaxSize(Long fileMaxSize) {
        this.fileMaxSize = fileMaxSize;
    }

    public String getFileAllowFiles() {
        return fileAllowFiles;
    }

    public void setFileAllowFiles(String fileAllowFiles) {
        this.fileAllowFiles = fileAllowFiles;
    }

    public String getFileManagerUrlPrefix() {
        return fileManagerUrlPrefix;
    }

    public void setFileManagerUrlPrefix(String fileManagerUrlPrefix) {
        this.fileManagerUrlPrefix = fileManagerUrlPrefix;
    }

    public String getFileManagerActionName() {
        return fileManagerActionName;
    }

    public void setFileManagerActionName(String fileManagerActionName) {
        this.fileManagerActionName = fileManagerActionName;
    }

    public String getFileManagerListPath() {
        return fileManagerListPath;
    }

    public void setFileManagerListPath(String fileManagerListPath) {
        this.fileManagerListPath = fileManagerListPath;
    }

    public String getFileManagerAllowFiles() {
        return fileManagerAllowFiles;
    }

    public void setFileManagerAllowFiles(String fileManagerAllowFiles) {
        this.fileManagerAllowFiles = fileManagerAllowFiles;
    }

    public Integer getFileManagerListSize() {
        return fileManagerListSize;
    }

    public void setFileManagerListSize(Integer fileManagerListSize) {
        this.fileManagerListSize = fileManagerListSize;
    }

    public String getMediaUrlPrefix() {
        return mediaUrlPrefix;
    }

    public void setMediaUrlPrefix(String mediaUrlPrefix) {
        this.mediaUrlPrefix = mediaUrlPrefix;
    }

    public String getMediaFieldName() {
        return mediaFieldName;
    }

    public void setMediaFieldName(String mediaFieldName) {
        this.mediaFieldName = mediaFieldName;
    }

    public String getMediaActionName() {
        return mediaActionName;
    }

    public void setMediaActionName(String mediaActionName) {
        this.mediaActionName = mediaActionName;
    }

    public Long getMediaMaxSize() {
        return mediaMaxSize;
    }

    public void setMediaMaxSize(Long mediaMaxSize) {
        this.mediaMaxSize = mediaMaxSize;
    }

    public String getMediaPathFormat() {
        return mediaPathFormat;
    }

    public void setMediaPathFormat(String mediaPathFormat) {
        this.mediaPathFormat = mediaPathFormat;
    }

    public String getMediaAllowFiles() {
        return mediaAllowFiles;
    }

    public void setMediaAllowFiles(String mediaAllowFiles) {
        this.mediaAllowFiles = mediaAllowFiles;
    }

    public String getToolbars() {
        return toolbars;
    }

    public void setToolbars(String toolbars) {
        this.toolbars = toolbars;
    }

    public String getServerUrl() {
        return serverUrl;
    }

    public void setServerUrl(String serverUrl) {
        this.serverUrl = serverUrl;
    }

    public String getValue(Field field) {
        try {
            field.setAccessible(Boolean.TRUE);
            Object value = field.get(this);
            if (value == null) {
                if (value instanceof Number) {
                    return "0";
                } else {
                    return "";
                }
            } else {
                return value.toString();
            }
        } catch (Exception e) {
            return "";
        }
    }


}
